/*
 * Copyright (c) 2001-2006 Accenture LLC.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Accenture. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Accenture.
 *
 * ACCENTURE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ACCENTURE
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package org.tigris.jelements;

import org.tigris.mappedlexer.exception.UnexpectedEndOfFileException;
import org.tigris.mappedlexer.validator.*;

/**
 * @author zhisen.huang
 * 
 */
public class CompilationUnitProduction extends AbstractProduction {

	Production importProduction = null;

	Production classProduction = null;

	public void parse() throws Exception {
		lexer.nexttok("package");
		tk = lexer.nexttok(VerifyHub.IDENTIFIER);
		lexer.nexttok(";");

		while (true) {
			importProduction.setLexer(lexer);
			importProduction.parse();
			tk = lexer.nexttok();
			lexer.backward(tk);
			if (!tk.equals("import")) {
				break;
			}
		}

		while (true) {
			classProduction.setLexer(lexer);
			classProduction.parse();
			try {
				tk = lexer.nexttok();
			} catch (UnexpectedEndOfFileException ex) {
				return;
			}
			lexer.backward(tk);
		}
	}

	/**
	 * @param classProduction the classProduction to set
	 */
	public void setClassProduction(Production classProduction) {
		this.classProduction = classProduction;
		this.classProduction.setLexer(lexer);
	}

	/**
	 * @param importProduction the importProduction to set
	 */
	public void setImportProduction(Production importProduction) {
		this.importProduction = importProduction;
		this.importProduction.setLexer(lexer);
	}

}
